package com.capinfo.accumulation.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class DateUtil {
	public static Date getDate(String source ,String pattern) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.parse(source);
	}
	
	public static String  getFormatDate(Date date ,String pattern) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(date);
	}
	
	
	public static String addM(Date date) throws ParseException{
		System.out.println(date.toString());
		    Calendar   calendar   =   new   GregorianCalendar(); 
		    calendar.setTime(date); 
		    //calendar.add(calendar.YEAR, 1);//把日期往后增加一年.整数往后推,负数往前移动
		    calendar.add(calendar.MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
		   // calendar.add(calendar.DATE,1);//把日期往后增加一天.整数往后推,负数往前移动 
		   // calendar.add(calendar.WEEK_OF_MONTH, 1);//把日期往后增加一个月.整数往后推,负数往前移动
		    date=calendar.getTime();   //这个时间就是日期往后推一天的结果 
		    System.out.println(date.toString());
		    return  DateUtil.getFormatDate(date,"yyyyMM");
	}
	
	
	public static void main(String[] args) throws ParseException {
		System.out.println(addM(new Date()));
	}
}
